﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BullsEyeGame
{
    /// <summary>
    /// A form that lets the user choose the number of guesses he wants and finally start the game
    /// </summary>
    internal class FormRoundsSelector : Form
    {
        private const int k_ComponentPadding = 8;
        private const string k_TitleOfForm = "Bool Pgia";
        private const int k_WidthOfForm = 250;
        private const int k_HightOfForm = 130;
        private const string k_ButtonChancesCounterText = "Number of chances: ";
        private const string k_ButtonStartText = "Start";

        private Button m_ButtonChancesCounter = new Button();
        private Button m_ButtonStart = new Button();
        private int m_NumberOfGuessesChosen = GameLogics.MinNumberOfGuesses;
        
        /// <summary>
        /// A constructor of the form round selector
        /// </summary>
        public FormRoundsSelector()
        {
            initializeComponent();
        }
        
        /// <summary>
        /// Property to get the number of guesses chosen
        /// </summary>
        public int NumberOfGuessesChosen 
        {
            get { return m_NumberOfGuessesChosen; }
        }

        private void initializeComponent()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Size = new Size(k_WidthOfForm, k_HightOfForm);
            this.Text = k_TitleOfForm;
            this.Visible = false;

            initializeChancesCounterButton();
            initializeStartButton();
        }

        private void initializeStartButton()
        {
            int left, top;
            m_ButtonStart.Text = k_ButtonStartText;
            left = this.ClientSize.Width - (m_ButtonStart.Width + k_ComponentPadding);
            top = this.ClientSize.Height - (m_ButtonStart.Height + k_ComponentPadding);
            m_ButtonStart.Location = new Point(left, top);
            m_ButtonStart.Click += m_ButtonStart_Click;
            this.Controls.Add(m_ButtonStart);
        }

        private void initializeChancesCounterButton()
        {
            m_ButtonChancesCounter.Text = k_ButtonChancesCounterText + m_NumberOfGuessesChosen;
            m_ButtonChancesCounter.Location = new Point(k_ComponentPadding, k_ComponentPadding);
            m_ButtonChancesCounter.Width = this.ClientSize.Width - (2 * k_ComponentPadding);
            m_ButtonChancesCounter.Click += m_ButtonChancesCounter_Click;
            this.Controls.Add(m_ButtonChancesCounter);
        }

        private void m_ButtonChancesCounter_Click(object sender, EventArgs e)
        {
            if (m_NumberOfGuessesChosen < GameLogics.MaxNumberOfGuesses)
            {
                ++m_NumberOfGuessesChosen;
                m_ButtonChancesCounter.Text = k_ButtonChancesCounterText + m_NumberOfGuessesChosen;
            }
        }

        private void m_ButtonStart_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}